home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / pcfig4th.arc / SIEVE.SCR < prev    next >
Text File  |  1985-04-23  |  3KB  |  1 lines

  1.                                                                                                                                                                                                                                                                                                                                              Eratosthene's sieve:                                                                                                           prime number generator,                                                                                                             and benchmark                                                                                                                                                                                                                                                                                                                                                                                                                                   ( Eratosthenes sieve, BYTE 9/81, FD 3:181 )                     FORTH DEFINITIONS                                               ( --   generate the first 1899 prime numbers >3 )               8190 CONSTANT SIZE  SIZE STRING FLAGS                           : PRIME 0 FLAGS SIZE 1 FILL                                         0 SIZE 0 DO                                                       I FLAGS C@ IF                                                     I DUP + 3 +                                                     DUP I +                                                         BEGIN DUP SIZE < WHILE                                            0 OVER FLAGS C! OVER +                                        REPEAT DROP DROP 1+                                           ENDIF                                                         LOOP CR . ." primes " ;                                     -->                                                                                                                             ( Sieve, cont. )                                                0 VARIABLE KOUNT                                                : NEW-LINE CR 0 OUT ! ; : NL? OUT @ 70 > IF NEW-LINE ENDIF ;    : P-TEST 0 KOUNT !                                                  ET0 10 0 DO PRIME LOOP ET(S) NEW-LINE                           SIZE 0 DO                                                         I FLAGS C@                                                      IF I DUP + 3 +                                                    7 .R NL? 1 KOUNT +!                                           ENDIF                                                         LOOP CR KOUNT ? ." primes checked  " ;                      ;S